﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Quality.Records
{
    public partial class selecteq : Form
    {
        public selecteq()
        {
            InitializeComponent();
            frm_TransfEvent();
        }

        private void 查询toolStripButton1_Click(object sender, EventArgs e)
        {
            frm_TransfEvent();
        }
        void frm_TransfEvent()
        {
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = new SqlCommand();
            if (keytoolStripTextBox.Text == "")
            {

                da.SelectCommand.CommandText = "select  a.id,a.num,a.eqname,b.nodeName,c.num num1,c.workname from equipments a left join organization b on a.orgnum=b.id left join workcenters c on a.worknum=c.num where a.stop=0 order by a.orgnum,a.worknum,a.num  desc";

            }
            else
            {

                da.SelectCommand.CommandText = "select a.id,a.num,a.eqname,b.nodeName,c.num num1,c.workname from equipments a left join organization b on a.orgnum=b.id left join workcenters c on a.worknum=c.num  where a.num like '%@key%' or a.eqname like '%@key%' and stop=0 order by a.orgnum,a.worknum,a.num desc";
                da.SelectCommand.Parameters.AddWithValue("@key", keytoolStripTextBox.Text.Trim());

            }
            DataSet dt = DB.getlist(da);
            dataGridView1.DataSource = dt.Tables[0];

        }
        public event TransfDelegate TransfEvent;
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            string[] d = new string[2];
            if (dataGridView1.SelectedRows.Count > 0)
            {           
                d[0] = dataGridView1.CurrentRow.Cells[1].Value.ToString();
                d[1] = dataGridView1.CurrentRow.Cells[2].Value.ToString();
                TransfEvent(d);
                this.Close();

            }
        }

    }
}
